package ch.uzh.ifi.seal.ssqa.importer.versioncontrol;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import net.sourceforge.clearcase.commandline.CommandLauncher;
import net.sourceforge.clearcase.commandline.CommandLine;
import net.sourceforge.clearcase.commandline.Response;

import org.eclipse.jface.preference.IPreferenceStore;

import ch.uzh.ifi.seal.ssqa.SsqaPlugin;
import ch.uzh.ifi.seal.ssqa.preferences.PreferenceConstants;

/**
 * A command to execute Clearcase statements at the console over the Clearcase tool of sourceforge
 * @author marckorsgen
 *
 */
public class ClearCaseCommand {
	/*
	 * The commandline that should be executed.
	 */
	private CommandLine cline;
	
	public final static String SUCCEED = "succeed";
	public final static String FAIL = "fail";
	
	/*
	 * to execute a commandline we need an 
	 */
	private CommandLauncher launcher;
	
	public ClearCaseCommand(CommandLine cmd){
		this.cline = cmd;
		this.launcher = new CommandLauncher();
	}
	
/*	public Response execute(){
		IPreferenceStore store = SsqaPlugin.getDefault().getPreferenceStore();
		try{
			Response r = launcher.execute(cline.create(), new File(store.getString(PreferenceConstants.CC_VIEW_DEVICE)+":\\"), null, null);
			return r;
		}catch(Exception e){
			e.printStackTrace();
		}
		return null;
	}*/
	
	public Map<String,String[]> execute(){
		Map<String,String[]> result = new HashMap<String,String[]>();
		IPreferenceStore store = SsqaPlugin.getDefault().getPreferenceStore();
		
		//FIXME: Thread controlling to prevent freezing screen
		
		Response r = launcher.execute(cline.create(), new File(store.getString(PreferenceConstants.CC_VIEW_DEVICE)+":\\"),null,null);
		result.put(ClearCaseCommand.SUCCEED, r.getStdOutMsg());
		result.put(ClearCaseCommand.FAIL, r.getStdErrMsg());
		return result;
	}
}
